<?php
//系统通知
if(!defined('IN_T')){
   die('hacking attempt');
}

//编辑、添加通知
if($act=='edit'){
	$tid = intval($_REQUEST['tid']);
	$row = $Db->query("select * from ".$Base->table('tag')." where id=$tid",'Row');
	if(empty($_POST)){
		$tp->assign('row',$row);
		$sql = "select * from ".$Base->table('tag')." where type=1 and notice ='' order by id desc";
		$res = $Db->query($sql);
		$tp->assign('res',$res);
	}
	else{
		$data = array(
			'notice'=>Common::sfilter($_POST['notice']),
			'href'=>Common::sfilter($_POST['href']),
			'time_s'=>Common::sfilter($_POST['time_s']),
			'time_e'=>Common::sfilter($_POST['time_e']),
		);
		$res['status'] = 0;
		if(empty($data['notice'])){
			$res['msg'] = '请填写通知内容';
		}
		else if(!strtotime($data['time_s'])){
			$res['msg'] = '请选择开始时间';
		}
		else if(!strtotime($data['time_e'])){
			$res['msg'] = '请选择结束时间';
		}
		else{
			$Db->update($Base->table('tag'),$data,array('id'=>$tid));
			$res = array('status'=>1,'msg'=>'编辑成功','href'=>'/'.TONGJI_PATH.'/?m=notice');
		}
		echo $Json->encode($res);
		exit;
	}
}
//删除通知
else if($act=='delete'){
	$tid = intval($_REQUEST['tid']);
	$sql = "update ".$Base->table('tag')." set notice='',href='',time_s=null,time_e=null where id=$tid";
	$Db->execSql($sql);
	echo $Json->encode(array('status'=>1));
	exit;
}
//显示通知
else{
	$sql = "select * from ".$Base->table('tag')." where type=1 and notice !='' order by id desc";
	$res = $Db->query($sql);
	$tp->assign('res',$res);
}
$tp->assign('nav','系统通知');
?>